package com.hjm.ui.goods;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hjm.ui.R;

/**
 * 商品简介
 * 也就是商品名+价格部分
 */
public class GoodsIntro extends LinearLayout {
    private TextView goodsNameTextView, goodsPriceTextView;
    public GoodsIntro(Context context) {
        super(context);
        init();
    }

    public GoodsIntro(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GoodsIntro);
        String goodsNameText = a.getString(R.styleable.GoodsIntro_nameText);
        String goodsPriceText = a.getString(R.styleable.GoodsIntro_priceText);
        if (goodsNameText != null) {
            goodsNameTextView.setText(goodsNameText);
            goodsPriceTextView.setText(goodsPriceText);
        }
    }

    public GoodsIntro(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    private void init() {
        // 在这里添加你的布局和逻辑
        LayoutInflater.from(getContext()).inflate(R.layout.layout_goods_intro, this, true);
        goodsNameTextView = findViewById(R.id.text_view_goods_name);
        goodsPriceTextView = findViewById(R.id.text_view_goods_price);
    }

    public void setGoodsName(String name) {
        goodsNameTextView.setText(name);
    }

    public void setGoodsPrice(String price) {
        goodsPriceTextView.setText(price);
    }
}
